package com.neusoft.neuiotms.dcvm.task.cmdbSyn.respository.impl;

import java.util.List;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.neuiotms.dcvm.task.cmdbSyn.model.CmdbSynSrcData;
import com.neusoft.neuiotms.dcvm.task.cmdbSyn.model.QCmdbSynSrcData;
import com.neusoft.neuiotms.dcvm.task.cmdbSyn.model.QCmdbSynSrcDataLast;
import com.neusoft.neuiotms.dcvm.task.cmdbSyn.respository.CustomizedCmdbSynDataRepository;

public class CustomizedCmdbSynDataRepositoryImpl extends AbstractRepository
        implements CustomizedCmdbSynDataRepository {

    @Override
    protected Class<?> getModelClass() {
        return CmdbSynSrcData.class;
    }

    @Override
    public List<CmdbSynSrcData> searchUpdate(final String assetType) {
        final QCmdbSynSrcData qCmdbSynSrcData = QCmdbSynSrcData.cmdbSynSrcData;
        final QCmdbSynSrcDataLast qCmdbSynSrcDataLast = QCmdbSynSrcDataLast.cmdbSynSrcDataLast;
        final List<CmdbSynSrcData> result = this.query().selectFrom(qCmdbSynSrcData).rightJoin(qCmdbSynSrcDataLast)
                .on(qCmdbSynSrcData.coding.eq(qCmdbSynSrcDataLast.coding),
                        qCmdbSynSrcDataLast.synCmdb.eq("1"))
                .where(qCmdbSynSrcData.coding.isNotNull(), qCmdbSynSrcData.assetType.eq(assetType))
                .fetch();
        return result;
    }

    @Override
    public List<CmdbSynSrcData> searchAdd(final String assetType) {
        final QCmdbSynSrcData qCmdbSynSrcData = QCmdbSynSrcData.cmdbSynSrcData;
        final QCmdbSynSrcDataLast qCmdbSynSrcDataLast = QCmdbSynSrcDataLast.cmdbSynSrcDataLast;
        final List<CmdbSynSrcData> result = this.query().selectFrom(qCmdbSynSrcData).leftJoin(qCmdbSynSrcDataLast)
                .on(qCmdbSynSrcData.coding.eq(qCmdbSynSrcDataLast.coding),
                        qCmdbSynSrcDataLast.synCmdb.eq("1"))
                .where(qCmdbSynSrcDataLast.coding.isNull(), qCmdbSynSrcData.assetType.eq(assetType))
                .fetch();
        return result;
    }

}
